package org.pine.common.beans;

import org.slf4j.MDC;

/**
 * 日志ID
 *
 * @author pine
 * @version 1.0
 * @since 2025-04-10 18:10
 */
public class LogId {
    public static final String LOG_ID_KEY = "logId";

    private LogId() {
    }

    public static void put(String logId) {
        MDC.put(LOG_ID_KEY, logId);
    }

    public static String get() {
        String logId = MDC.get(LOG_ID_KEY);
        if (logId == null) {
            logId = generate();
            put(logId);
        }

        return logId;
    }

    public static void remove() {
        MDC.remove(LOG_ID_KEY);
    }

    public static String generate() {
        return IdGenerator.nextIdStr();
    }

    public static String suffix(Object suffix) {
        return get() + "-" + suffix;
    }

    public static String prefix(Object prefix) {
        return prefix + "-" + get();
    }

}
